import { BallColor } from './BallAttribute';
import { UserOutLookAtrribute } from './OutLookAttribute';
import { UserAttribute } from './UserAttribute';
export class PlayUser {
  static TypeHuman = 0;
  static TypeAiRobot = 1;
  static TypeNetHuman = 2;

  static StatusInit = 0;
  static StatusPrepared = 1;
  static StatusStarted = 2;
  static StatusEnded = 3;
  static StatusLeaved = 4;

  public color = new BallColor(0); // 0 未区分 1 全色 2 双色

  public type = 0; // 0 当前用户 1 机器人  2 网络用户
  public status = PlayUser.StatusInit; // 0 未知 1 已进入 2 开始 3 游戏结束 4 离开房间
  public score = 0; // 分数值， 斯诺克得分
  public startStepTime = 0; // 当前走棋开始的时间戳
  public userAttribute: UserAttribute = null;
  public outlookAttribute: UserOutLookAtrribute = null;
  static newRobotUser(c: number, user: UserAttribute) {
    return new PlayUser(c, PlayUser.TypeAiRobot, user);
  }
  static newHumanUser(c: number, user: UserAttribute) {
    return new PlayUser(c, PlayUser.TypeHuman,  user);
  }

  constructor(color: number, type: number, userAttribute: UserAttribute) {
    this.color.color = color; // 击球的颜色
    this.type = type; // 0 当前用户 1 机器人  2 网络用户
    this.status = PlayUser.StatusInit; // 0 未知 1 已进入 2 开始 3 游戏结束 4 离开房间
    this.startStepTime = (new Date()).valueOf(); // 当前走棋开始的时间戳
    this.userAttribute = userAttribute;
    this.score = 0;
    this.outlookAttribute = new UserOutLookAtrribute("DefaultQiuGan");
  }

  initGame() {
    this.color.initColor();
    this.score = 0;
    this.restartStepTime();
  }
  initRedColor() {
    this.color.initRedColor();
  }
  initAnyColor() {
    this.color.initAnyColor();
  }
  initSpecialColor() {
    this.color.initSpecialColor();
  }
  human() {
    this.type = PlayUser.TypeNetHuman;
    return this;
  }

  robot() {
    this.type = PlayUser.TypeAiRobot;
    return this;
  }

  isInitedStatus() {
    return this.status === PlayUser.StatusInit;
  }
  isLeavedStatus() {
    return this.status === PlayUser.StatusLeaved;
  }
  isPreparedStatus() {
    return this.status === PlayUser.StatusPrepared;
  }
  isStartedStatus() {
    return this.status === PlayUser.StatusStarted;
  }
  prepared() {
    this.status = PlayUser.StatusPrepared;
    return this;
  }

  started() {
    this.status = PlayUser.StatusStarted;
  }

  ended() {
    this.status = PlayUser.StatusEnded;
  }
  
  leaved() {
    this.status = PlayUser.StatusLeaved;
    return this;
  }

  restartStepTime() {
    this.startStepTime = (new Date()).valueOf();
  }

  isRobot() {
    return this.type === PlayUser.TypeAiRobot;
  }

  isMyMove(sd: number) {
    return this.color.color === sd;
  }
  swapColor() {
    this.color.swapColor();
  }
  addScore(s: number) {
    this.score += s;
  }
}